*final update 2025.02.03



********************************************************************************
//STEP 01: CREATE LOCALS
********************************************************************************
*Directory to the Alpha_Do_File .do file's location
local 	home_folder "/Users/demattee/Desktop/JLC_Replication"

local MA		"5"					// What is MA's id_city? UNSURE: tab id_city if hearing_base_city=="BOS", nolab
local units		"24"				// How many jurisdictions are there?

//IDENTIFY THE STATING DATES
local begin		"1"					// The first id_time in the analysis
local MSPEstart "1"					// Period in which MSPE minimization begins 														
		
//IDENTIFY THE TREATMENT DATES
local pretreat	"38"				// What id_time corresponds with the Brito vs. Barr decision date
local decision	"39"				// Brito vs. Barr opinion published (Wednesday, Nov 27, 2019).
										// id_time	time	date_day
										// 32		201948	2019.11.27
									// court orders that immigration courts shall follow the requirements, effective Friday, December 13, 2019.
										// id_time	time	date_day
										// 34		201950	2019.12.13
local posttreat "40"				// What is the first id_time after the decision date? UNSURE: decision +1

//IDENTIFY THE ENDING DATES
local endtime	"52"				// id_time 53==2020 week 12 (Friday, March 20th) as the last id_time in the analysis?
local covid		"52"				// POTUS Declares COVID-19 a National Emergency (Friday, March 13).
										
//Set locals to ensure that all analyses run the same model
local outcome 	"granted_bond"													 
local pretime 	"granted_bond(13) granted_bond(17) granted_bond(20) granted_bond(38)"
local court		"trump_ij obama_ij ij_experience"								
local case		"crime_charge_yes meeting_number"								
local econ		"log_state_gdp"													
local society	"log_state_pop state_govt_employees_capita"	



********************************************************************************
// STEP 02: FIND MONTHLY P-VALUE FOR BOSTON
********************************************************************************

*Tell Stata where to save these .dta files it generates
cd "`home_folder'/Data/Placebo Results Granted Bond/Weekly"	

use "synth_placebo_bond_weekly_graph.dta", clear

//Graph the Fisher-exact p-values of the sample
/*
The Fisher-exact P value corresponds to the proportion of values of the test 
statistic that are as extreme (i.e., as unusual) or more extreme than the observed 
value of that test statistic. The minimum attainable Fisher-exact P value, 
P value_min, that can be achieved is 1/Nrandomizations. */

foreach i of numlist 1/`units' {	 
	gen lessextreme_BOS_`i' = 0
		by week: replace lessextreme_BOS_`i' = 1 if diff_`i' <= diff_`MA'					// flags whether diff_`i' is more positive than MA in that period
// 		by week: replace lessextreme_BOS_`i' = 1 if diff_`i' >=diff_`MA'	& diff_`MA'>0	// flags whether diff_`i' is less extreme than MA in that period, and MA is positive 
// 		by week: replace lessextreme_BOS_`i' = 1 if diff_`i' <=diff_`MA'	& diff_`MA'<0	// flags whether diff_`i' is less extreme than MA in that period, and MA is negative
// 		by week: replace lessextreme_BOS_`i' = 1 if abs(diff_`i') >= abs(diff_`MA')			// flags whether diff_`i' is more extreme than MA in that period
}
egen 	oneside_pvalue = rowtotal(lessextreme_BOS_1-lessextreme_BOS_`units')					// 
		replace oneside_pvalue = oneside_pvalue/`units' 										// one-sided p-value for MA treatment effect
		drop lessextreme*

graph twoway	/// (qfit oneside_pvalue week if week >=`posttreat')	///
				(scatter oneside_pvalue week if week>=`posttreat', mcolor(black) msymbol(smsquare)),			///
				title("Negative Treatment Effect on Rate Granted Bond (Fisher-exact P-values)", size(small)) 	///
				subtitle("Proportion of values as/more negative than Boston's Treatment Effect (`units' Hearing Base Cities)", size(vsmall)) 			///
				caption("") note("$S_DATE", size(tiny) span)													///
				xtitle("", size(small)) 																		///					
					xline(`decision', lwidth(medthick) lpattern(dot) lcolor(red))		///
					/// yline(`decision', lpattern(dash) lcolor(red))											///	
					/// yline(`covid', lwidth(medthick) lpattern(tight_dot) lcolor(black))						///
					ylabel(0(.2)1, grid labsize(small)) xmtick(##1) 												///
				ytitle("Treatment Effect Significance") 														///
					xlabel(`decision'(1)`endtime', labsize(small) angle(horizontal) valuelabel gmin gmax) ymtick(##2) 			///
					/// yline(0, lpattern(solid) lcolor(gs10))													///
					graphregion(c(gs16)) 																		///
				plotregion(ic(gs16)) 																			//
// 				legend(on order(2 "Boston" 1 "Fitted Values")													///
// 						cols(1) size(vsmall) nobox region(fcolor(none) lcolor(gs12)) 							///
// 						position(1) ring(0))
				graph save "Graph" 	"`home_folder'/Graphs/pvalues_bond_weekly.gph", replace	
				graph export 		"`home_folder'/Graphs/pvalues_bond_weekly.jpg", as(jpg) name("Graph") replace


			
********************************************************************************
// STEP 03: Return to JLC_01a_Synth_Granted_Bond_Weekly.do
********************************************************************************						
